<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
					xmlns:DentalGUIHelper="clr-namespace:DentalGUIHelper;assembly=DentalConfig"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="../Brushes/MaterialDesign/MaterialDesignTheme.Theme.xaml"/>
    <ResourceDictionary Source="../NamedStyles/MaterialDesignTheme.NamedTextBlock.xaml"/>
    <ResourceDictionary Source="MaterialDesignTheme.Shadows.xaml" />
    <ResourceDictionary>
      <converters:BrushRoundConverter x:Key="BrushRoundConverter"/>
    </ResourceDictionary>
  </ResourceDictionary.MergedDictionaries>

  <converters:EqualityToVisibilityConverter x:Key="EqualityToVisibilityConverter" />

  <Style x:Key="FocusVisual">
    <Setter Property="Control.Template">
      <Setter.Value>
        <ControlTemplate>
          <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignToolToggleListBoxItem" TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
      <Style x:Key="{x:Type TextBlock}" BasedOn="{StaticResource ControlContentTextblock}" TargetType="{x:Type TextBlock}"/>
    </Style.Resources>
    <Setter Property="Background" Value="{DynamicResource MaterialDesignCardBackground}"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignDivider}"/>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Stretch}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Center}"/>
    <Setter Property="Padding" Value="14 6 14 6" />
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  Margin="{TemplateBinding Margin}"
                  ClipToBounds="{TemplateBinding ClipToBounds}">
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup Name="CommonStates">
                <VisualStateGroup.Transitions>
                  <VisualTransition GeneratedDuration="0:0:0.05" To="Normal">
                    <VisualTransition.GeneratedEasingFunction>
                      <CircleEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                  </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState Name="Normal"/>
                <VisualState Name="MouseOver">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="Opacity"
                                     To="0.1" Duration="0"/>
                  </Storyboard>
                </VisualState>
                <VisualState Name="Disabled"/>
              </VisualStateGroup>
              <VisualStateGroup Name="SelectionStates">
                <VisualStateGroup.Transitions>
                  <VisualTransition From="*" To="Selected">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackgroundBorder">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualTransition>
                  <VisualTransition From="*" To="SelectedUnfocused">
                    <Storyboard>
                      <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackgroundBorder">
                        <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                      </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                  </VisualTransition>
                  <VisualTransition From="Selected" To="Unselected">
                    <Storyboard>
                      <DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
                                       Storyboard.TargetProperty="Opacity"
                                       To="0" Duration="0"/>
                    </Storyboard>
                  </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState Name="Selected">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
                                     Storyboard.TargetProperty="Opacity"
                                     To="1" Duration="0"/>
                  </Storyboard>
                </VisualState>
                <VisualState Name="Unselected"/>
                <VisualState Name="SelectedUnfocused">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="SelectedBackgroundBorder"
                                     Storyboard.TargetProperty="Opacity"
                                     To="1" Duration="0"/>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid>
              <Border x:Name="MouseOverBorder"
                      Opacity="0"
                      Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"/>
              <Border x:Name="SelectedBackgroundBorder"
                      Opacity="0"
                      ClipToBounds="True"
                      Background="{DynamicResource SecondaryAccentBrush}">
                <Border x:Name="InnerShadowBorder" Background="Transparent" BorderBrush="#000000" BorderThickness="1" Margin="-5">
                  <Border.Effect>
                    <DropShadowEffect ShadowDepth="0" BlurRadius="10"/>
                  </Border.Effect>
                </Border>
              </Border>
              <wpf:Ripple x:Name="Ripple" Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
                          Opacity=".56"
                          Focusable="False"
                          Content="{TemplateBinding Content}"
                          ContentTemplate="{TemplateBinding ContentTemplate}"
                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                          Padding="{TemplateBinding Padding}">
              </wpf:Ripple>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsSelected" Value="True">
              <Setter TargetName="Ripple" Property="Opacity" Value=".92" />
              <Setter Property="Foreground" Value="{DynamicResource SecondaryAccentForegroundBrush}"/>
            </Trigger>
      			<Trigger Property="IsMouseOver" Value="true">
      				<Setter Property="DentalGUIHelper:MouseBehavior.IsMouseOver" Value="True"/>
      			</Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignToolToggleListBox" TargetType="{x:Type ListBox}">
    <Setter Property="Background" Value="{DynamicResource MaterialDesignDivider}"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="wpf:ListBoxAssist.IsToggle" Value="False" />
    <Setter Property="DentalGUIHelper:ListBoxHelper.DisableUnselectLast" Value="True" />
    <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth1" />
    <Setter Property="HorizontalContentAlignment" Value="Left"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="ItemContainerStyle" Value="{StaticResource MaterialDesignToolToggleListBoxItem}"/>
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBox}">
          <ControlTemplate.Resources>
            <Style TargetType="{x:Type wpf:PackIcon}" >
              <Setter Property="Width" Value="22" />
              <Setter Property="Height" Value="22" />
            </Style>
          </ControlTemplate.Resources>
          <Border x:Name="Bd"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  SnapsToDevicePixels="true"
                  Padding="{TemplateBinding Padding}">
            <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
              <Border x:Name="maskBorder" CornerRadius="2" Background="{DynamicResource MaterialDesignPaper}"/>
              <Grid Background="{TemplateBinding Background}" wpf:ShadowAssist.ShadowDepth="{TemplateBinding wpf:ShadowAssist.ShadowDepth}" Effect="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}">
                <Grid.OpacityMask>
                  <VisualBrush Visual="{Binding ElementName=maskBorder}" TileMode="None" Stretch="None" AlignmentX="Left" AlignmentY="Top"/>
                </Grid.OpacityMask>
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
              </Grid>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsGrouping" Value="true"/>
                <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
              </MultiTrigger.Conditions>
              <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </MultiTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignStretchedToolToggleListBox" TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignToolToggleListBox}">
    <Setter Property="HorizontalAlignment" Value="Stretch"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="ItemsPanel">
      <Setter.Value>
        <ItemsPanelTemplate>
          <UniformGrid Rows="1"/>
        </ItemsPanelTemplate>
      </Setter.Value>
    </Setter>
    <Setter Property="ItemContainerStyle">
      <Setter.Value>
        <Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource MaterialDesignToolToggleListBoxItem}">
          <Setter Property="HorizontalContentAlignment" Value="Center"/>
        </Style>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignToolToggleFlatListBox" TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignToolToggleListBox}">
    <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth0" />
  </Style>

  <Style x:Key="MaterialDesignListBoxItem" TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
      <Style x:Key="{x:Type TextBlock}" BasedOn="{StaticResource ControlContentTextblock}" TargetType="{x:Type TextBlock}"/>
    </Style.Resources>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Stretch}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Center}"/>
    <Setter Property="Padding" Value="8"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <Border Background="{TemplateBinding Background}"
                  BorderBrush="{TemplateBinding BorderBrush}"
                  BorderThickness="{TemplateBinding BorderThickness}"
                  Margin="{TemplateBinding Margin}"
                  ClipToBounds="{TemplateBinding ClipToBounds}">
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup Name="CommonStates">
                <VisualStateGroup.Transitions>
                  <VisualTransition GeneratedDuration="0:0:0.05" To="Normal">
                    <VisualTransition.GeneratedEasingFunction>
                      <CircleEase EasingMode="EaseOut"/>
                    </VisualTransition.GeneratedEasingFunction>
                  </VisualTransition>
                </VisualStateGroup.Transitions>
                <VisualState Name="Normal"/>
                <VisualState Name="MouseOver">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="Opacity"
                                         To="0.1" Duration="0"/>
                  </Storyboard>
                </VisualState>
                <VisualState Name="Disabled"/>
              </VisualStateGroup>
              <VisualStateGroup Name="SelectionStates">
                <VisualStateGroup.Transitions>
                  <VisualTransition GeneratedDuration="0:0:0.1"/>
                </VisualStateGroup.Transitions>
                <VisualState Name="Selected">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="SelectedBorder"
                                     Storyboard.TargetProperty="Opacity"
                                     To="0.3" Duration="0"/>
                  </Storyboard>
                </VisualState>
                <VisualState Name="Unselected"/>
                <VisualState Name="SelectedUnfocused">
                  <Storyboard>
                    <DoubleAnimation Storyboard.TargetName="SelectedBorder"
                                     Storyboard.TargetProperty="Opacity"
                                     To="0.18" Duration="0"/>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid>
              <Border x:Name="MouseOverBorder"
                      Opacity="0"
                      Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"/>

              <Border x:Name="SelectedBorder"
                      Opacity="0"
                      Background="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
                      RenderTransformOrigin="0.5,0.5">
                <Border.RenderTransform>
                  <ScaleTransform ScaleX="1"/>
                </Border.RenderTransform>
              </Border>
              <wpf:Ripple Feedback="{TemplateBinding Foreground, Converter={StaticResource BrushRoundConverter}}"
                          Focusable="False"
                          Content="{TemplateBinding Content}"
                          ContentTemplate="{TemplateBinding ContentTemplate}"
                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                          HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                          VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                          Padding="{TemplateBinding Padding}">
                <wpf:Ripple.Resources>
                  <system:Double x:Key="DisabledOpacity">1</system:Double><!--TextBlock disabled opacity should not be applied on top of HintOpacity-->
                </wpf:Ripple.Resources>
              </wpf:Ripple>
            </Grid>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsEnabled" Value="False">
              <Setter Property="Opacity" Value="{StaticResource DisabledOpacity}" />
            </Trigger>
			<Trigger Property="IsMouseOver" Value="true">
				<Setter Property="DentalGUIHelper:MouseBehavior.IsMouseOver" Value="True"/>
			</Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignCardsListBoxItem" TargetType="{x:Type ListBoxItem}">
    <Style.Resources>
      <Style x:Key="{x:Type TextBlock}" BasedOn="{StaticResource ControlContentTextblock}" TargetType="{x:Type TextBlock}"/>
    </Style.Resources>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Padding" Value="0"/>
    <Setter Property="Margin" Value="0 0 8 8"></Setter>
    <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Stretch}"/>
    <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}, FallbackValue=Center}"/>
    <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBoxItem}">
          <wpf:Card Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    ContentStringFormat="{TemplateBinding ContentStringFormat}"
                    ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"/>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignListBox" TargetType="{x:Type ListBox}">
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="BorderBrush" Value="Transparent"/>
    <Setter Property="BorderThickness" Value="0"/>
    <Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}"/>
    <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
    <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
    <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
    <Setter Property="ScrollViewer.PanningMode" Value="Both"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    <Setter Property="VerticalContentAlignment" Value="Center"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ListBox}">
          <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
            <ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
              <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
            </ScrollViewer>
          </Border>
          <ControlTemplate.Triggers>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsGrouping" Value="true"/>
                <Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
              </MultiTrigger.Conditions>
              <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </MultiTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="MaterialDesignOutlinedListBox" TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignListBox}">
    <Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignDivider}"/>
    <Setter Property="BorderThickness" Value="1"/>
  </Style>

  <Style x:Key="MaterialDesignCardsListBox" TargetType="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignListBox}">
    <Setter Property="ItemContainerStyle" Value="{StaticResource MaterialDesignCardsListBoxItem}"/>
  </Style>

  <Style x:Key="{x:Type ListBoxItem}" BasedOn="{StaticResource MaterialDesignListBoxItem}" TargetType="{x:Type ListBoxItem}" />
  <Style x:Key="{x:Type ListBox}" BasedOn="{StaticResource MaterialDesignOutlinedListBox}" TargetType="{x:Type ListBox}" />

</ResourceDictionary>
